package org.pattern.abstractFactory.model;


public class HeMan implements ActionFigure {
	private Integer health;
	
	public HeMan(Integer health){
		if(health < MIN_HEALTH || health > MAX_HEALTH)
			throw new IllegalArgumentException("Health is outside of valid range");
		
		this.health = health;
	}
	
	@Override
	public Integer attack() {
		return (int) (Math.random() * MAX_DAMAGE);
	}

	@Override
	public void defend(Integer damage) {
		if(damage > MAX_DAMAGE || damage < 0)
			throw new IllegalArgumentException("Damage is outside of valid range");
		
		Integer defend = (int) (Math.random() * MAX_DEFEND);
	
		if(! (defend > damage))
			health -= damage - defend;
	}

	@Override
	public boolean isDead() {				
		return (health <= 0);
	}
	
	@Override
	public String getName() {
		return "Heman";
	}
	
	@Override
	public Integer getHealth() {
		return health;
	}
}